package org.nod.atgm.model;

import org.nod.atgm.GameManager;
import org.nod.atgm.gameobjects.APC;
import org.nod.atgm.gameobjects.CircularPropeller;
import org.nod.atgm.gameobjects.StatefulGameObject;

import com.threed.jpct.SimpleVector;

public class SpawnManager {
	
	protected static final int ENEMY_SPAWN_INTERVAL = 30000; //Spawn interval. Should use some class for this later
	
	protected static final float SPEED_DEMULTIPLIER = 1000f;
	
	protected static final float ENEMY_CIRCULAR_MIN_DISTANCE = 50f;
	protected static final float ENEMY_CIRCULAR_MAX_DISTANCE = 100f;
	
	protected static final float ENEMY_CIRCULAR_MIN_SPEED = 0.5f;
	protected static final float ENEMY_CIRCULAR_MAX_SPEED = 2f;
	
	protected static int timeCounter = ENEMY_SPAWN_INTERVAL;
//	protected static SimpleVector initialPosition = new SimpleVector(-20f,-2.5f,0f);
	protected static SimpleVector initialPosition = new SimpleVector(-20f,-5f,0f);
	protected static SimpleVector initialDirection = new SimpleVector(1f,0f,0f);
	protected static StatefulGameObject[] emtyArray = new StatefulGameObject[0];
	
	public static StatefulGameObject[] spawnDestroyableObjects(long timeDelta) {
		timeCounter += timeDelta;
		if (timeCounter >= ENEMY_SPAWN_INTERVAL) {
			timeCounter = 0;
			APC apc = new APC(initialPosition,initialDirection,0.002f);
			float distance = (float) (ENEMY_CIRCULAR_MIN_DISTANCE + Math.random() * (ENEMY_CIRCULAR_MAX_DISTANCE - ENEMY_CIRCULAR_MIN_DISTANCE));
			float speed = (float) (ENEMY_CIRCULAR_MIN_SPEED + Math.random() * (ENEMY_CIRCULAR_MAX_SPEED - ENEMY_CIRCULAR_MIN_SPEED)) / SPEED_DEMULTIPLIER;
			apc.setPropeller(new CircularPropeller(apc,GameManager.CAM_CENTER,distance,-speed,(float)(5 * Math.PI / 4), (float)(- Math.PI / 4), -2f)); //(float)( 7 * Math.PI / 4)
			return new StatefulGameObject[]{apc};
		}
		return emtyArray;
	}
}
